package com.shhm.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shhm.common.entity.system.SysMenu;
import com.shhm.common.entity.system.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/7/16 下午3:46
 */
@Mapper
public interface SysUserRoleMapper extends BaseMapper<UserRole> {
    @Select("SELECT  sr.role_name,sr.role_key " +
            "FROM sys_user_role sur " +
            "LEFT JOIN sys_role sr ON sur.role_id = sr.role_id " +
            "WHERE sur.user_id = #{userId}")
    List<UserRole> selectRolesByUserId(Long userId);

    @Select("SELECT sm.menu_id,sm.menu_name,sm.parent_id,sm.order_num,sm.name,sm.path,sm.component,sm.perms,sm.icon "+
            "FROM sys_user_role sur "+
            "LEFT JOIN sys_role sr ON sur.role_id = sr.role_id "+
            "LEFT JOIN sys_role_menu srm ON sr.role_id=srm.role_id "+
            "left JOIN sys_menu sm ON srm.menu_id=sm.menu_id "+
            "WHERE sur.user_id = #{uid}  AND sm.menu_id IS NOT NULL And sm.visible=1")
    List<SysMenu> selectMenuByUser(Long uid);
}
